﻿@using KendoGridWithCascadingComboBoxes.Models;
@{
    ViewBag.Title = "Home Page";
}

@(Html.Kendo().Grid<License>()
      .Name("Grid")        
      .Columns(columns =>
      {
          columns.Bound(p => p.CustomerId).Width(400).HeaderHtmlAttributes(new { @title = "Customer" });
          columns.Bound(p => p.VendorId).Width(400).HeaderHtmlAttributes(new { @title = "Vendor" });
          columns.Bound(p => p.ProductId).HeaderHtmlAttributes(new { @title = "Product" });
      })
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          toolbar.Save();
      })
      .Editable(editable => editable.Mode(GridEditMode.InCell))
      .Events(e => e.Edit("edit"))
      .DataSource(dataSource => dataSource
          .Ajax()
          .Batch(true)
          .ServerOperation(false)
          .Model(model => model.Id(p => p.LicenseId))
              .Read(read => read.Action("Read", "Home").Type(HttpVerbs.Post))
              .Create(create => create.Action("Create", "Home").Type(HttpVerbs.Post))
              .Update(update => update.Action("Update", "Home").Type(HttpVerbs.Post))
          )
)

<script>
    function edit(e) {
        var container = e.container,
            model = e.model,
            ddl = container.find("[data-role=dropdownlist]").data("kendoDropDownList"),
            cascadeFrom;

        if (ddl) {
            cascadeFrom = ddl.options.cascadeFrom;

            if (cascadeFrom) {
                ddl.dataSource.filter({
                    field: cascadeFrom,
                    operator: "eq",
                    value: model[cascadeFrom]
                });
            }
        }
    }
</script>